package com.lagou.rpc.consumer.controller;

import com.lagou.rpc.api.IUserService;
import com.lagou.rpc.consumer.client.lb.ClientLoadBalancer;
import com.lagou.rpc.consumer.proxy.RpcClientProxy;
import com.lagou.rpc.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xingyi
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private ClientLoadBalancer clientLoadBalancer;

    @GetMapping("findById")
    User findById(Integer id) {
        IUserService userService = (IUserService) RpcClientProxy.createProxy(clientLoadBalancer, IUserService.class);
        final User user = userService.getById(id);
        return user;
    }

}
